package Chapter01.Homework.Work04;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Work04 {
    List<Student> list=new ArrayList();
    List<Student> list02=new LinkedList();
    public void add(){
        for (int i=0;i<100000;i++){
            list.add(new Student("小方"));
            System.out.println("ArrayList完成");
        }
        for (int i=0;i<100000;i++){
            list02.add(new Student("小方"));
            System.out.println("LinkedList完成");
        }
    }
    public void delete(){
        long time=System.currentTimeMillis();
        for (int i =0; i<100; i++){
            int a= (int) (Math.random()*100000);
            list.remove(a);
            System.out.println("ArrayList删除");
        }
        long time1=System.currentTimeMillis();
        long zhi=time1-time;
        long time3=System.currentTimeMillis();
        for (int i =0; i<100; i++){
            int a= (int) (Math.floor(100000*Math.random()) + 1);
            list02.remove(a);
            System.out.println("LinkedList删除");
        }
        long time04=System.currentTimeMillis();
        long num=time04-time3;
        System.out.println("Array需时间："+zhi);
        System.out.println("Linked需时间："+num);
    }

    public static void main(String[] args) {
        Work04 am=new Work04();
        am.add();
        am.delete();
    }
}
